home *** CD-ROM | disk | FTP | other *** search
- Path: po.CWRU.Edu!mab22
- From: mab22@po.CWRU.Edu (Michael A. Balfour)
- Newsgroups: comp.lang.c
- Subject: Re: Variant Records in C ... Is there a way ?
- Date: 22 Mar 1996 17:02:31 GMT
- Organization: Case Western Reserve University, Cleveland, OH (USA)
- Message-ID: <4iumf8$604@madeline.INS.CWRU.Edu>
- References: <Pine.OSF.3.91.960319170252.9783B-100000@alfa.ist.utl.pt> <315006F8.639@cmt.lpr.mail.carel.fi>
- Reply-To: mab22@po.CWRU.Edu (Michael A. Balfour)
- NNTP-Posting-Host: kanga.ins.cwru.edu
-
-
- In a previous article, aril@cmt.lpr.mail.carel.fi (Ari Lukumies) says:
-
- >How about something like:
- >
- > struct {
- > int flag;
- > union {
- > char text[80];
- > int num;
- > double fpoint;
- > } data;
- > } test;
- >
-
- Wasn't the original goal of the variant records to avoid chewing up
- extra memory? As I understand it, union uses as much memory as the
- largest member. In this case, even if you are only storing an int, you
- still use 80 bytes, right?
-
- So my answer to the poster is that there is no mechanism in C
- specifically designed to handle variant records using only as much
- memory as data.
-
- *However*, if you feel like it, you can still do it yourself with some
- clever mallocs and overlaying structures. Not exactly elegant, but you
- can make it pretty memory-efficient.
-
- Mike Balfour
-
- --
- ----------------------------------+--------------------------------
- Mike Balfour, Partner | BS/MS Graduate - ECMP
- Overload Engineering | Case Western Reserve University
- "New Ideas for a Brighter Future" | Cleveland, OH
-